package dryven.view.engine.parser.componentinvocation;

import java.util.HashMap;
import java.util.Map;

import dryven.view.engine.parser.CompilationException;
import dryven.view.engine.parser.ViewDataDeclarationCollection;

public class AttributeBindings {
	
	private Map<String, AttributeBinding> _bindings = new HashMap<String, AttributeBinding>();
	
	public Iterable<String> getBindingNames() {
		return _bindings.keySet();
	}
	public AttributeBinding getBindingByName(String name) {
		return _bindings.get(name);
	}
	
	public void addBinding(String name, String value) {
		if(value.startsWith("${")) {
			_bindings.put(name, new ExpressionAttributeBinding(value));
		} else {
			_bindings.put(name, new TextAttributeBinding(value));
		}
	}
	
	public void compile(ViewDataDeclarationCollection declarations) throws CompilationException {
		for (AttributeBinding binding : _bindings.values()) {
			binding.compile(declarations);
		}
	}
}
